package com.gj.config;

import com.gj.bean.Color;
import com.gj.bean.ColorFactoryBean;
import com.gj.bean.Person;
import com.gj.condition.MyImportBeanDefinitionRegistrar;
import com.gj.condition.MyImportSelector;
import com.gj.condition.linuxCondition;
import com.gj.condition.windowsCondition;
import org.springframework.context.annotation.*;
import org.springframework.stereotype.Component;

//@Configuration
@Import({Color.class, MyImportSelector.class, MyImportBeanDefinitionRegistrar.class}) // @Import快速地导入组件，id默认是组件的全类名
public class Mainconfig2 {

    @Bean("person")
    @Lazy
    //@Scope("prototype")//多实例
    public Person person(){
        System.out.println("创建person实例");

        return new Person("zhangsan",15);
    }

    @Conditional({windowsCondition.class})
    @Bean("Bill")
    public Person person01(){
        return new Person("Bill",56);
    }

    @Conditional({linuxCondition.class})
    @Bean("linus")
    public Person person02(){
        return new Person("linus",48);
    }

    //把工厂类写到配置类
    @Bean
    public ColorFactoryBean colorFactoryBean() {
        return new ColorFactoryBean();
    }
}
